#include "leecode.h"
#include <string_view>
#include <string>

class Solution {
public:
  vector<string> letterCombinations(string digits) {
    vector<string> ret;
    int size = 1;
    int digit_size = digits.size();
    if (digit_size == 0)
      return {""};
    char s = digits.at(0);
    auto temp = GetString(s);
    for (int i = 0; i < temp.size(); i++)
      ret.push_back(std::string(temp.data() + i, 1));


    for (int i = 1; i < digit_size; i++) {
      auto t2 = GetString(digits[i]);
      vector<string> ret2;
      for (int j = 0; j < ret.size(); j++) {
        for (int k = 0; k < t2.size(); k++) {
          std::string s = ret[j];
          s.push_back(t2[k]);
          ret2.push_back(s);
        }
      }
      ret = std::move(ret2);
    }

    return ret;
  }

  void Init();

  std::string GetString(char x) {
    int pos = x - '2';
    return m_dict[pos];

  }


//  std::map<char, std::string> m_dict;
  std::vector<std::string> m_dict;
};


void Solution::Init()
{
  m_dict = {
    std::string("abc", 3),
    std::string("def", 3),
    std::string("ghi", 3),
    std::string("jkl", 3),
    std::string("mno", 3),
    std::string("pqrs", 4),
    std::string("tuv", 3),
    std::string("wxyz", 4)
  };
}


TEST(letterCombinations, combin1) {
  GTEST_SKIP();
  std::string digits = "23";
  Solution s;
  s.Init();
  auto ret = s.letterCombinations(digits);

  std::cout << "input is :" << digits << endl;
  std::cout << "output is :" << endl;
  for (int i = 0; i < ret.size(); i++) {
    std::cout << ret[i] << ",";
  }
  std::cout << endl;
}

TEST(letterCombinations, combin2) {
  GTEST_SKIP();
  std::string digits = "2";
  Solution s;
  s.Init();
  auto ret = s.letterCombinations(digits);

  std::cout << "input is :" << digits << endl;
  std::cout << "output is :" << endl;
  for (int i = 0; i < ret.size(); i++) {
    std::cout << ret[i] << ",";
  }
  std::cout << endl;
}